package Thread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Demo27 {
    public static void main(String[] args) {
        BlockingQueue<String> queue = new LinkedBlockingQueue<>(1000);
        //至少一个生产者线程，一个消费者线程
        Thread producer = new Thread(()->{
            String str = "小野猫已经开始依恋我";
            while (true){
                try {
                    queue.put(str);
                    System.out.println("生产出的语句："+str);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        //消费者
        Thread consumer = new Thread(()->{
            while (true){
                try {
                  String s=  queue.take();
                    System.out.println("消费者产生的语句："+s);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        producer.start();
        consumer.start();
    }
}
